
function lightbox(img) {
    var shadow = document.createElement('div');
    shadow.className = 'shadow';
    var lightbox = document.createElement('div');
    lightbox.className = 'lightbox';
    var image = document.createElement('img');
    image.src = img;
    document.body.appendChild(shadow);
    shadow.onclick = function() {
        document.body.removeChild(shadow);
        document.body.removeChild(lightbox);
    };
    lightbox.onclick = function() {
        document.body.removeChild(shadow);
        document.body.removeChild(lightbox);
    };
    document.body.appendChild(lightbox);
    lightbox.appendChild(image);
}

function lightboxContent(content, scroll) {
    var shadow = document.createElement('div');
    shadow.className = 'shadow';
    var lightbox = document.createElement('div');
    lightbox.className = 'lightbox ' + (scroll ? 'scrollable' : 'fixedcontent');
    document.body.appendChild(shadow);
    document.body.appendChild(lightbox);
    shadow.onclick = function() {
        document.body.removeChild(shadow);
        document.body.removeChild(lightbox);
    };
    lightbox.innerHTML = content;
    return lightbox;
}

function closeLightBox() {
    $('.lightbox').remove();
    $('.shadow').remove();
}

function lightboxAjaxContent(url, params, scroll) { // 'params' can be the FormName containing the params (inputs)
    if (typeof params === 'string') {
        if (document.forms[params] && formValuesToArray !== undefined) {
            params = formValuesToArray(params);
        } else {
            params = {};
        }
    }
    if (!params) {
        params = {};
    }
    var lightbox = lightboxContent('', scroll);

    if (typeof loadAjax !== 'undefined') {
        loadAjax(url, params, lightbox);
        return lightbox;
    }
    if (jQuery && $(lightbox).load) {
        $(lightbox).load(url, params);
        return lightbox;
    }
}